<template>
  <div class="headoffice-group">
    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="24">
        <div class="headoffice-wrapper">
          <div class="headoffice-wrapper-content">
            <div class="group-itembox">
              <div class="group-item">
                <div class="card-headoffice">
                  <div class="card-headoffice-description">
                    <div class="card-headoffice-text">收款金额</div>
                    <div class="card-headoffice-num">{{ dailData.payment }}</div>
                  </div>
                </div>
              </div>
              <div class="group-item">
                <div class="card-headoffice">
                  <div class="card-headoffice-description">
                    <div class="card-headoffice-text">订单数量</div>
                    <div class="card-headoffice-num">{{ dailData.orderNumber }}</div>
                  </div>
                </div>
              </div>
              <div class="group-item">
                <div class="card-headoffice">
                  <div class="card-headoffice-description">
                    <div class="card-headoffice-text">订单金额</div>
                    <div class="card-headoffice-num">{{ dailData.orderment }}</div>
                  </div>
                </div>
              </div>
              <div class="group-item">
                <div class="card-headoffice">
                  <div class="card-headoffice-description">
                    <div class="card-headoffice-text">采购流水</div>
                    <div class="card-headoffice-num">{{ dailData.procurement }}</div>
                  </div>
                </div>
              </div>
              <div class="group-item">
                <div class="card-headoffice">
                  <div class="card-headoffice-description">
                    <div class="card-headoffice-text">开户数量</div>
                    <div class="card-headoffice-num">{{ dailData.userInfoNumber }}</div>
                  </div>
                </div>
              </div>
              <div class="group-item">
                <div class="card-headoffice">
                  <div class="card-headoffice-description">
                    <div class="card-headoffice-text">开店数量</div>
                    <div class="card-headoffice-num">{{ dailData.shopNumber }}</div>
                  </div>
                </div>
              </div>
              <div class="group-item">
                <div class="card-headoffice">
                  <div class="card-headoffice-description">
                    <div class="card-headoffice-text">代理数量</div>
                    <div class="card-headoffice-num">{{ dailData.agentInfoNumber }}</div>
                  </div>
                </div>
              </div>
              <div class="group-item">
                <div class="card-headoffice">
                  <div class="card-headoffice-description">
                    <div class="card-headoffice-text">分公司数量</div>
                    <div class="card-headoffice-num">{{ dailData.branchOfficeInfoNumber }}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>

    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper">
          <p>近七天订单量</p>
          <order-chart ref="orderChart" :chartData="weekData"/>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper">
          <p>近七天订单额量</p>
          <amount-chart ref="amountChart" :chartData="weekPayAmountData"/>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper">
          <p>近一个月销售类目</p>
          <category-chart ref="categoryChart" :chartData="monthCategoryData"/>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper">
          <p>近一个月销售国家</p>
          <country-chart ref="countryChart" :chartData="monthCountryData"/>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import CountTo from 'vue-count-to'
import {
  ErpLastMonthCategoryData, ErpLastMonthCountryData,
  ErpLastWeekPayAmountData,
  ErpOrderWeekData,
  HeadOfficeDailData
} from "@/api/index/index"
import OrderChart from "@/views/dashboard/OrderChart.vue";
import AmountChart from "@/views/dashboard/AmountChart.vue";
import CategoryChart from "@/views/dashboard/CategoryChart.vue";
import CountryChart from "@/views/dashboard/CountryChart.vue";

export default {
  components: {
    CountTo,
    OrderChart,
    AmountChart,
    CategoryChart,
    CountryChart,
  },
  data() {
    return {
      dailData: {},
      weekData: {},
      weekPayAmountData: {},
      monthCategoryData: [],
      monthCountryData: []
    }
  },
  created() {
    this.getErpOrderWeekData();
    this.getErpLastWeekPayAmountData();
    this.getErpLastMonthCategoryData();
    this.getErpLastMonthCountryData();
    this.getHeadOfficeDailData();
  },
  methods: {
    // 近七日订单量
    getErpOrderWeekData() {
      ErpOrderWeekData().then(res => {
        this.weekData = res.data;
        this.$nextTick(() => {
          this.$refs.orderChart.initChart();
        })
      })
    },
    // 近七天支付金额量
    getErpLastWeekPayAmountData() {
      ErpLastWeekPayAmountData().then(res => {
        this.weekPayAmountData = res.data;
        this.$nextTick(() => {
          this.$refs.amountChart.initChart();
        })
      })
    },
    // 近一个月销售类目占比
    getErpLastMonthCategoryData() {
      ErpLastMonthCategoryData().then(res => {
        this.monthCategoryData = res.data.series;
        this.$nextTick(() => {
          this.$refs.categoryChart.initChart();
        })
      })
    },
    // 近一个月销售国家占比
    getErpLastMonthCountryData() {
      ErpLastMonthCountryData().then(res => {
        this.monthCountryData = res.data.series;
        this.$nextTick(() => {
          this.$refs.countryChart.initChart();
        })
      })
    },
    // 实时数据
    getHeadOfficeDailData() {
      HeadOfficeDailData().then(res => {
        this.dailData = res.data;
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.headoffice-group {
  .headoffice-wrapper {
    background: #fff;
    padding: 20px 16px 0;
    margin-bottom: 32px;

    p {
      font-size: 16px;
      line-height: 18px;
      margin: 0 0 15px;
      color: #666;
    }

    .headoffice-wrapper-content {
      padding: 10px 0 30px;
    }
  }

  .group-itembox {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -16px;

    .group-item {
      width: calc(100% / 4);
      padding: 0 16px;
      margin: 10px 0;
    }
  }

  .card-headoffice-col {
    margin-bottom: 32px;
  }

  .card-headoffice {
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    .card-headoffice-description {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      font-weight: bold;
      padding: 26px;

      .card-headoffice-text {
        line-height: 20px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 10px;
      }

      .card-headoffice-num {
        font-size: 20px;
        line-height: 20px;
      }
    }
  }

  .card-headoffice-item {
    height: 200px;
  }

  .card-headoffice-item-padding {
    padding: 0 30px;
  }

  .card-headoffice-textbold {
    font-size: 26px;
    font-weight: bold;
  }

  .card-headoffice-text300 {
    font-size: 24px;
  }

  .card-headoffice-button {
    flex: 1;
    padding-left: 80px;

    .button-item {
      display: inline-block;
      line-height: 40px;
      font-size: 20px;
      color: #36a3f7;
      padding: 0 15px;
      margin: 0 5px;
      cursor: pointer;
      border-radius: 6px;

      &:hover {
        background: #36a3f7;
        color: #fff;
      }
    }
  }

  .fontSize16 {
    font-size: 16px;
    line-height: 18px;
  }

  .card-headoffice-flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .card-headoffice-flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .card-headoffice-flex-column {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
  }
}

@media (max-width: 550px) {
  .card-headoffice-description {
    display: none;
  }

  .card-headoffice-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
